package com.example.geek.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.webkit.WebSettings;

import com.example.geek.R;
import com.example.geek.jsbridge.BridgeHandler;
import com.example.geek.jsbridge.BridgeWebView;
import com.example.geek.jsbridge.CallBackFunction;

@SuppressLint("SetJavaScriptEnabled")
public class WebActivity extends AppCompatActivity {
    private BridgeWebView bridgeWebView;
    private String url;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        bridgeWebView = findViewById(R.id.bridgeWebView);

        Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            url = bundle.getString("url");
        }

        WebSettings settings = bridgeWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        bridgeWebView.loadUrl(url);

        bridgeWebView.registerHandler("goback", new BridgeHandler() {
            @Override
            public void handler(String data, CallBackFunction function) {
                finish();
            }
        });
    }
}